package cn.itlaobing.web.servlet;

import cn.itlaobing.exception.MyException;
import cn.itlaobing.model.AreasModel;
import cn.itlaobing.model.GoodDetailModel;
import cn.itlaobing.model.GoodsDetailModel;
import cn.itlaobing.service.OrderDetailsService;
import cn.itlaobing.web.annotation.RequestMapping;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017-11-13.
 */
@WebServlet("/home/*")
public class OrderDetailsServlet extends BaseServlet{
    private OrderDetailsService orderDetailsService=new OrderDetailsService();
        @RequestMapping("/nishuone")
        public void hotSaleProductDetail(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
            Map<String,List> map =null;
            try {
                map=orderDetailsService.getIndex();
            } catch (MyException e) {
                e.printStackTrace();
            }
            request.setAttribute("HOTSALEPRODUCTDETAIL_REQUEST",map);
            request.getRequestDispatcher("/WEB-INF/views/order/index.jsp").forward(request,response);
        }
        @RequestMapping("/goodDetail")
        public void goodDetail(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
           String Id=request.getParameter("goodId");
            Integer id=Integer.parseInt(Id);
            List<String> list=null;
            GoodsDetailModel goodsDetailModel=null;
            List<AreasModel> areaList=null;
            try {
                areaList=orderDetailsService.queryAll();
                list=orderDetailsService.detailImg(id);
               goodsDetailModel=orderDetailsService.queryDetailByid(id);


            } catch (MyException e) {
                e.printStackTrace();
            }
            request.setAttribute("AREA_REQUEST",areaList);
            request.setAttribute("DETAILIMG",list);
            request.setAttribute("GOODDETAILMODEL" ,goodsDetailModel);
            request.getRequestDispatcher("/WEB-INF/views/order/detail.jsp").forward(request,response);
        }
        @RequestMapping("/skipLogin")
        public void skipLogin(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
            System.out.println(1);
            request.getRequestDispatcher("/WEB-INF/views/order/login/login.jsp").forward(request,response);
        }
        @RequestMapping("/skipRegister")
        public void skipRegister(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            System.out.println(2);
            request.getRequestDispatcher("/WEB-INF/views/order/login/register.jsp").forward(request,response);
        }
}
